package com.example.wac.config;

import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.scheduling.annotation.EnableAsync;
import org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor;

/**
 * @author wuancheng
 * @description
 * @date 2021-11-24 17:54:00
 */

@Configuration
@EnableAsync
public class ExecutorConfig {
    public ExecutorConfig() {
    }

    @Bean(name = "threadPoolTaskExecutor")
    public ThreadPoolTaskExecutor threadPoolTaskExecutor() {
        ThreadPoolTaskExecutor threadExecutor = new ThreadPoolTaskExecutor();
        threadExecutor.setCorePoolSize(9);
        threadExecutor.setMaxPoolSize(100);
        threadExecutor.setQueueCapacity(200);
        threadExecutor.setKeepAliveSeconds(60);
        threadExecutor.setThreadNamePrefix("sendEmail");
        //threadExecutor.setRejectedExecutionHandler(new ThreadRejectedHandler("Reject-ThreadExecutor"));
        return threadExecutor;
    }
}
